package com.nowcoder.community.util;

public class RedisKeyUtil {
    private static final String SPLIT=":";
    //点赞实体
    private static final String PREFIX_ENTITY_LIKE="like:entity";

    private static final String PREFIX_USER_LIKE = "like:user";

    //A关注B，A是B的粉丝（follower），B是A的目标（followee）
    private static final  String PREFIX_FOLLOWEE="followee";
    private static final String PREFIX_FOLLOWER = "follower";

    private static final String PREFIX_KAPTCHA = "kaptcha";
    private static final String PREFIX_TICKET = "ticket";
    private static final String PREFIX_USER = "user";
    /**
     * 某个实体的赞
     * 实现结果 like:entity:entityType:entityId -> set(userId)
     * @author ProgramCat
     * @date 2023/4/4 8:27
     * @param entityType 点赞类型（1-帖子，2-评论）
     * @param entityId 帖子id
     * @return String 对应的Key值
     */
    public static String getEntityLikeKey(int entityType,int entityId){
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    /**
     *某个用户的赞
     * @author ProgramCat
     * like:user:userId -> int
     * @date 2023/4/4 11:28
     * @param userId 用户id
     * @return String
     */
    public static String getUserLikeKey(int userId){
        return PREFIX_USER_LIKE+SPLIT+userId;
    }

    /**
     *  某个用户关注的实体
     *   followee:userId:entityType -> zset(entityId,now)
     * @author ProgramCat
     * @date 2023/4/6 20:13
     * @param userId 用户id
     * @param entityType 关注的实体类型
     * @return String 关注数量
     */
    public static String getFolloweeKey(int userId,int entityType){
        return PREFIX_FOLLOWEE+SPLIT+userId+SPLIT+entityType;
    }
    /**
     * 某个实体拥有的粉丝
     * follower:entityType:entityId -> zset(userId,now)
     * @author ProgramCat
     * @date 2023/4/6 20:15
     * @param entityType 实体的类型
     * @param entityId 实体的id
     * @return String 拥有的粉丝数量
     */
    public static String getFollowerKey(int entityType, int entityId) {
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }

    /**
     * 登录 验证码
     * @author ProgramCat
     * @date 2023/4/7 17:01
     * @param owner 验证码
     * @return String
     */
    public static String getKaptchaKey(String owner){
        return PREFIX_KAPTCHA+SPLIT+owner;
    }
    /**
     * 登录凭证
     * @author ProgramCat
     * @date 2023/4/7 17:20
     * @param ticket 登录凭证
     * @return String
     */
    public static String getTicketKey(String ticket) {
        return PREFIX_TICKET + SPLIT + ticket;
    }

    /**
     * 用户
     * @author ProgramCat
     * @date 2023/4/7 17:21
     * @param userId 用户id
     * @return String
     */
    public static String getUserKey(int userId) {
        return PREFIX_USER + SPLIT + userId;
    }

}
